This code provides two examples of spatial data visualization for oil spill data in California. The exploratory data visualization is in an interactive format, while the choropleth map is a static map in a finalized format. Both highlight how the same data can be shown in different ways to visualize different aspects of the spatial data. For example, the full data set is likely useful for interactive exploration, but would make for a messy map if we were trying to convey counts in an easy to understand format. A choropleth makes the data easy to interpret by obscures the exact location a spill occurred.
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
# attach libraries
library(spatstat)
library(tmap)
library(tmaptools)
library(sf)
library(tidyverse)
library(here)
# spill data
spills <- read_sf(here('data', 'Oil_Spill_Incident_Tracking_[ds394]', "Oil_Spill_Incident_Tracking_[ds394].shp")) %>%
janitor::clean_names()
# county shapefile
ca_counties <- read_sf(here('data', 'ca_counties', 'CA_Counties_TIGER2016.shp')) %>%
janitor::clean_names()
# interactive mode
tmap_mode('view')
# creation of exploratory map with both layers
tm_shape(ca_counties)+
tm_fill(col = 'black', alpha = 0.3)+
tm_borders(col = 'black', lwd = 0.5)+
tm_shape(spills) +
tm_dots()